from cryptography.fernet import Fernet

def encrypt_model_for_transfer(model):
    """
    加密模型以安全传输
    :param model: 模型参数
    :return: 加密后的模型和密钥
    """
    key = Fernet.generate_key()
    cipher_suite = Fernet(key)
    encrypted_model = cipher_suite.encrypt(model)
    return encrypted_model, key

# 示例
model = b"model_weights"
encrypted_model, key = encrypt_model_for_transfer(model)
print(f"Encrypted model: {encrypted_model}")